import {
    validate
} from './validate';
import {
    submit
} from './submit';

import {
    createView
} from './views/create.view';
import {
    getSectionInfo,renderSectionView
} from './renderSectionView';
import{
    modal
}from '../common/layer';
const createBtnHandler = () => {


    modal('新增', createView());


    $(".modal-form input").iCheck({
        checkboxClass: 'icheckbox_minimal-blue',
        radioClass: 'iradio_minimal-blue'
    });


    $('.is_copy').on('ifChecked', function(event){
        $('#copy_email').hide();
        let val = $('input:input[name="is_copy"]:checked').val();
        if(parseInt(val) === 1){
            $('#copy_email,#send_name').show();
        }else{
            $('#copy_email,#send_name').hide();
        }
    });

    $('#submitBtn').click(() => {
        let data = {};
        $.each($('#form').serializeArray(), (key, val) => {
            data[val.name] = $.trim(val.value);
        });
        if (!validate(data)) {
            return;
        }
        submit(GLOBAL_CreateUrl, data);
    });


};

export {
    createBtnHandler
}